#include <stdio.h>
#include <stdlib.h>

struct queue
{
    int *data, back, front, count, n;
};

void init_queue(struct queue *q, int n)
{
    q->data = (int *)malloc(sizeof(int) * n);
    if (q->data == NULL) //检查malloc返回值
        exit(1);
    q->n = n;
    q->front = q->back = q->count = 0;
}

void destroy_queue(struct queue *q)
{
    if (q->data != NULL)
        free(q->data);
    q->data = NULL; //释放后指针赋值为NULL
}

int is_full(struct queue *q)
{
    return q->count == q->n;
}

int is_empty(struct queue *q)
{
    return q->count == 0;
}

int enqueue(struct queue *q, int id)
{
    if (!is_full(q))
    {
        q->data[q->back] = id;
        q->back = (q->back + 1) % q->n;
        q->count++;
        return 1; //入队成功
    }
    return 0;
}

int dequeue(struct queue *q)
{
    if (!is_empty(q))
    {
        q->front = (q->front + 1) % q->n;
        q->count--;
        return 1; //出队成功
    }
    return 0;
}

int get_front(struct queue *q) //由调用者判断队列是否为空
{
    return q->data[q->front];
}

int main()
{
    int N, M;
    struct queue q;
    while (scanf("%d%d", &N, &M) == 2)
    {
        init_queue(&q, N);

        while (M--)
        {
            int op, id, ret;
            scanf("%d%d", &op, &id);
            if (op == 1) {
                ret = enqueue(&q, id);
            }
            else if (op == 2) {
                ret = dequeue(&q);
            }
            else {
                /* 工程项目中应当充分考虑未知情况进行错误处理 */
            }
        }

        if (is_empty(&q))
            printf("NULL\n");
        else {
            while (!is_empty(&q))
            {
                printf("%d ", get_front(&q));
                dequeue(&q);
            }
            printf("\n");
        }

        destroy_queue(&q);
    }
    return 0;
}
